import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/21 9:54
 * @description 思路，大顶堆
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int minStoneSum(int[] piles, int k) {
        int sum = 0;
        // 构建大顶堆
        PriorityQueue<Integer> pq = new PriorityQueue<>((a,b)-> b- a);
        for(int p: piles) {
            pq.add(p);
        }
        while (k > 0 && !pq.isEmpty()) {
            int n = pq.poll();
            n = n - n / 2;
            pq.add(n);
            k--;
        }
        for (int a: pq) {
            sum+= a;
        }
        return sum;
    }
}
